<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/8/16
  Time: 18:38
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD><TITLE>云和租房 - 首页</TITLE>
    <META content="text/html; charset=utf-8" http-equiv=Content-Type>
    <LINK rel=stylesheet type=text/css href="../css/style.css">
    <script src="/scripts/jquery-1.8.3.js"></script>
    <script src="/scripts/jQuery-2.2.0.min.js"></script>
    <script src="/scripts/distpicker.data.js"></script>
    <script src="/scripts/distpicker.js"></script>
    <META name=GENERATOR content="MSHTML 8.00.7601.17514">
</HEAD>
<BODY>
<DIV id=header class=wrap>
    <DIV id=logo><IMG src="../images/logo.gif"></DIV>
</DIV>
<DIV id=navbar class=wrap>
    <DL class="search clearfix">
        <FORM id=sform method=post action="/house/house_queryHouse">
            <DT>
                <UL>
                    <LI class=bold>房屋信息</LI>
                    <LI>标题：<INPUT class=text type=text name="house.title"> <LABEL class=ui-blue><INPUT onclick=doSearch()
                                                                                               value=搜索房屋 type="submit"
                                                                                               name=search></LABEL>
                    </LI>
                </UL>
            </DT>
            <DD>
                <UL>
                    <LI class=first>房屋位置</LI>
                    <LI ><div data-toggle="distpicker">
                        <div class="form-group">
                            <select class="form-control" id="province1" name="location.province"></select>
                        </div>
                        <div class="form-group">
                            <select class="form-control" id="city1" name="location.city"></select>
                        </div>
                        <div class="form-group">
                            <select class="form-control" id="district1" name="location.district"></select>
                        </div>
                    </div>
                    </LI>
                </UL>
            </DD>

            <DD>
                <UL>
                    <LI class=first>价格</LI>
                    <LI><SELECT name="price">
                        <OPTION selected value="">不限</OPTION>
                        <OPTION
                                value=0-100>100元以下
                        </OPTION>
                        <OPTION value=100-200>100元—200元</OPTION>
                        <OPTION value=200-1000000>200元以上</OPTION>
                    </SELECT></LI>
                </UL>
            </DD>
            <DD>
                <UL>
                    <LI class=first>房型</LI>
                    <LI><SELECT id="houseType" name="type.tname">
                        <OPTION selected value="">不限</OPTION>
                    </SELECT>
                    </LI>
                </UL>
            </DD>
            <DD>
                <UL>
                    <LI class=first>面积</LI>
                    <LI><SELECT name="area">
                        <OPTION selected value="">不限</OPTION>
                        <OPTION
                                value=0-40>40以下
                        </OPTION>
                        <OPTION value=40-500>40-500</OPTION>
                        <OPTION
                                value=500-1000000>500以上
                        </OPTION>
                    </SELECT></LI>
                </UL>
            </DD>



        </FORM>
    </DL>
</DIV>

<DIV class="main wrap">
    <TABLE class=house-list>
        <TBODY>
        <c:if test="${empty requestScope.list}">
            <span style="color: red">${requestScope.result}</span>
        </c:if>

        <c:forEach varStatus="s" var="h" items="${requestScope.list}">
            <TR>
                <TD class=house-thumb><span><a href="/house/getHouseById_getHouseById?house.hid=${h.hid}" target="_blank">
                <img src="../images/${h.pic}" width="100" height="75" alt="暂无图片"></a></span></TD>
                <TD>
                    <DL>
                        <DT><A href="/house/getHouseById_getHouseById?house.hid=${h.hid}" target="_blank">${h.title}</A></DT>
                        <DD>${h.describ}<BR>联系方式：${h.phone}</DD>
                    </DL>
                </TD>
                <TD class=house-type>${h.type.tname}</TD>
                <TD class=house-price><SPAN>${h.price}</SPAN>元/月</TD>
            </TR>
        </c:forEach>
        </TBODY>
    </TABLE>
    <DIV class=pager>
        <UL>
            <LI class=current><A href="#">首页</A></LI>
            <LI><A href="#">上一页</A></LI>
            <LI><A href="#">下一页</A></LI>
            <LI><A href="#">末页</A></LI>
        </UL>
        <SPAN
                class=total>1/2页</SPAN></DIV>
</DIV>
<DIV id=footer class=wrap>
    <DL>
        <DT>云和租房 © 2010 云和 京ICP证1000001号</DT>
        <DD>关于我们 · 联系方式 · 意见反馈 · 帮助中心</DD>
    </DL>
</DIV>
</BODY>
<script>
    $(function () {
        $.ajax({
            type:"post",
            url:"/house/houseInfo_getAllHouse",
            dataType:"JSON",
            success:function (data) {
                var arr = new Array();
                var result = new Array();
                $.each(data,function (index,obj) {
                    arr.push(obj.type.tname); //将房型放入集合中
                    result = unique(arr);  //去除重复项
                })
                for (var i=0;i<result.length;i++){
                    console.log(result[i]);
                    var option = "<option value='"+result[i]+"'>"+result[i]+"</option>";
                    $("#houseType").append(option);
                }
            }
        })
    })


    function unique(arr) { //数组去重函数
        var result = [];
        var obj = {};
        for(var i=0;i<arr.length;i++){
            if(!obj[arr[i]]){
                result.push(arr[i]);
                obj[arr[i]] = true;
            }
        }
        return result
    }
</script>

</HTML>
